<template>
  <div class="AdendDialog">
    <el-form ref="ruleForm" :model="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-row>
        <el-col :span="24">
          <el-form-item label="数据名称">
            <el-input v-model="ruleForm.dataName" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="数据类型">
            <el-input v-model="ruleForm.dataType" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="所属行业">
            <el-input v-model="ruleForm.industry"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="来源">
            <el-input v-model="ruleForm.source"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="状态">
            <el-switch v-model="ruleForm.status" active-color="#13ce66" inactive-color="#ff4949">
            </el-switch>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
        <el-button @click="resetForm('ruleForm')">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    props: {
      ranklist: {
        type: Function,
        default: null
      },
      close: {
        type: Function,
        default: null
      },
      row: {
        type: Object,
        default: () => {}
      }
    },
    mounted() {
      this.ruleForm = {
        ...this.row,
        status: this.row.status ? true : false
      }
    },
    data() {
      return {
        ruleForm: {
          dataName: "",
          dataType: "",
          industry: "",
          source: "",
          status: false,
          id: ''
        },
      }
    },
    methods: {
      // 表单提交
      submitForm() {
        this.$server
          .addList({
            dataName: this.ruleForm.dataName || this.row.dataName,
            dataType: this.ruleForm.dataType || this.row.dataType,
            industry: this.ruleForm.industry || this.row.industry,
            source: this.ruleForm.source || this.row.source,
            status: this.ruleForm.status ? 1 : 0,
            id: this.ruleForm.id,
          })
          .then((res) => {
            this.$message({
              type: "success",
              message: "修改成功!",
            });
          });
        this.close()
        this.ranklist()
      },
      resetForm() {
        this.close()
      },
    }
  }
</script>

<style>
</style>
